//
//  DMBaseTableViewController.swift
//  DM_新浪微博
//
//  Created by Damon.JiAo on 16/2/25.
//  Copyright © 2016年 Demon_JiAo. All rights reserved.
//

import UIKit

/** 只要继承此类的Controller都会执行ViewDidLoad里面的方法 */

class DMBaseTableViewController: UITableViewController,DMVisitorDelegate{
    /** 父类定义一个属性，子类可以访问 */
    var visitor:DMVisitor?
    
    
    override func loadView() {


        if DMUserViewModel.shareInstance.isLogin{
            
            print("11111111")
//            showVisitorView()
            super.loadView()
            
        }else{
            print("2222222")
//            super.loadView()
            showVisitorView()
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    
    /** 选择显示视图 */
    private func showVisitorView(){
        visitor = DMVisitor()
        
        visitor?.delegate = self
        
        visitor?.startAnimation()
        
        view = visitor
        
        setupNav()
    }
    
    private func setupNav(){
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "didRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "didLogin")

    }
    
    func loginClick() {
        
    }
    
    func registerClick() {
        print("控制器 代理回调")
        
        //
        let login = DMLoginViewController()
        
        let nav = UINavigationController(rootViewController: login)
        
        //
        presentViewController(nav , animated: true) { () -> Void in
            
        }
        
    }
}
